<?php
/**
 * Try to autoload a rail_* function or class file. 
 * Use spl_autoload_register to add to PHP __autoload() implementation.
 *
 **
 * PHP versions 5
 * See http://www.open-rail.org for more informations.
 *
 **
 * Copyright (C)
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of ERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software
 * Fundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
 *
 **
 * @author Bastian Schröder <bastian@open-rail.org>
 * @version 2009-05-12
 * @package rail
 */
function rail_autoload ( $pClassname ) {
	// only handle rail files
	if( substr( $pClassname, 0, 5 ) != 'rail_' )
		return;

	// requested a rail_exception class
	if( strpos( $pClassname, '_exception' ) ){
		include_once( "exceptions/$pClassname.class.php" );
		return;
	}

	// search rail class file
	$src = array( './', 'objects/', 'interfaces/' );
	$ext = array( '.class.php', '.inc.php' );

	foreach( $src as $path )
		foreach( $ext as $extension ){
			$file = PHPRAIL_BASEDIR . $path . $pClassname . $extension;
			if( is_file($file) ){
				include_once( $file );
				return;
			}
		}
}

// register autoload function
spl_autoload_register( 'rail_autoload' );
?>